<%--
  Created by IntelliJ IDEA.
  User: bin.liu
  Date: 2018/12/5
  Time: 11:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="/pages/sysIndex/default.jsp"/>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-trophy"></i> 审批管理
            </div>
            <div class="box-tools pull-right">
                <a href="#" class="btn btn-default" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
            </div>
        </div>

        <div class="box-body">
            <form id="searchForm" action="<c:url value="/web/admin/repairOrderAudit/listJson.action"/>" method="post"
                  class="form-inline hide" data-page-no="1" data-page-size="20" data-order-by="">
                <div class="form-group">
                    <label class="control-label">报修编号：</label>
                    <div class="control-inline">
                        <input type="text" id="searchReportCode" name="searchReportCode" value="" maxlength="64"
                               class="form-control width-200">
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label">报修内容：</label>
                    <div class="control-inline">
                        <input type="text" id="reportContent" name="reportContent" value="" maxlength="64"
                               style="width: 200px"
                               class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label">报修类型：</label>
                    <div class="control-inline" style="width:200px">
                        <select id="reportType" name="reportType" class="form-control">
                            <option value="" selected>&nbsp;全部&nbsp;&nbsp;&nbsp;</option>
                            <option value="COMMON_ORDER" >&nbsp;常规报修&nbsp;&nbsp;&nbsp;</option>
                            <option value="FACILITY_ORDER" >&nbsp;设备报修&nbsp;&nbsp;&nbsp;</option>
                            <option value="_400_ORDER" >&nbsp;400报修&nbsp;&nbsp;&nbsp;</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label">报&nbsp;&nbsp;修&nbsp;&nbsp;人：</label>
                    <div class="control-inline">
                        <input type="text" id="reportUser" name="reportUser" value="" maxlength="64"
                               style="width: 200px"
                               class="form-control">
                    </div>
                </div>

                <div class="form-group">
                    <button type="submit" class="btn btn-primary btn-sm">查询</button>
                    <button type="reset" class="btn btn-default btn-sm">重置</button>
                </div>
            </form>

            <div style="overflow-x:auto">
                <table id="dataGrid"></table>
            </div>
            <div id="dataGridPage"></div>
        </div>
    </div>
</div>
<script>
    var selectIds = [];
    $('#dataGrid').dataGrid({
        shrinkToFit: false,
        autoScroll: true,
        searchForm: $("#searchForm"),
        columnModel: [
            <sec:authorize access="hasRole('ROLE_ENTERPRISE_REPAIR_ORDER_AUDIT_EDIT')">
            {
                header: '操作',
                name: 'actions',
                width: 200,
                sortable: false,
                title: false,
                formatter: function (val, obj, row, act) {
                    var a="";
                    if((row.repairOrderType=='400报修'&&row.signDate!="")||row.repairOrderType!='400报修'|| ${signEnterpriseId}!=row.enterpriseId){
                        a='<a  class="btn btn-default btn-xs btnList" onclick="audit(' + row.id + ',true)" title="审批通过"><i class="fa fa-file-text-o"></i>审批通过</a>&nbsp;' +
                            '<a  class="btn btn-default btn-xs btnList" onclick="audit(' + row.id + ',false)" title="审批退回"><i class="fa fa-file-text-o"></i>审批退回</a>&nbsp;';
                    }else{
                        if(row.confirmDate==''){
                            a='<a  class="btn btn-default btn-xs btnList">确认维修中</a>';
                        }else if(row.signDate==''&&row.confirmDate!=''){
                            a='<a  class="btn btn-default btn-xs btnList">签字确认中</a>';
                        }
                    }
                    return  a;
                }
            },
            </sec:authorize>
            {header: '编号', name: 'reportCode', index: 'reportCode', width: 150, align: "center"},
            {header: '工单状态', name: 'orderStatus', index: 'orderStatus', width: 80, align: "center",sortable: false},
            {header: '工单类型', name: 'repairOrderType', index: 'repairOrderType', width: 80, align: "center",sortable: false},
            {header: '报修人', name: 'reportUser', index: 'reportUser', width: 80, align: "center"},
            {header: '报修地址', name: 'reportAddress', index: 'reportAddress', width: 150, align: "center"},
            {header: '报修内容', name: 'reportContent', index: 'reportContent', width: 300, align: "center"},
            {header: '客户报修人', name: 'customer', index: 'customer', width: 300, align: "center"},
            {header: '客户报修电话', name: 'callNumber', index: 'callNumber', width: 300, align: "center"},
            {header: '报修等级', name: 'reportLevel', index: 'reportLevel', width: 200, align: "center"},
            {header: '报修时间', name: 'createDate', index: 'createDate', width: 150, align: "center"},
            {header: '当前审核等级', name: 'auditLevel', index: 'auditLevel',hidden:true, width: 200, align: "center"},
            {header: '签字时间', name: 'signDate', index: 'signDate',hidden:true, width: 200, align: "center"},
            {header: '报修单类型', name: 'repairOrderType', index: 'repairOrderType',hidden:true},
            {header: '审批流等级', name: 'level', index: 'level', width: 200,hidden:true, align: "center"},
            {header: '专业', name: 'reportMajor', index: 'reportMajor', width: 200, align: "center"},
            {header: '部门', name: 'organizationName', index: 'organizationName', width: 80, align: "center",sortable: false},
            {header: '接单人', name: 'receiveUserName', index: 'receiveUserName', width: 80, align: "center",sortable: false},
            {header: '审批层数', name: 'flowSize', index: 'flowSize', width: 0, align: "center",hidden:true}// hidden:true 不显示该列

        ],
        // onselectRow:function(id){
        //     var ids = $("#dataGrid").jqGrid("getGridParam", "selarrrow");
        //     if(ids.contains(id)){
        //
        //     }
        // },
        // 加载成功后执行事件
        ajaxSuccess: function (data) {

        },
    });


    function audit(id, type) {
        if(!type){//審批退回
            vLayuiUtil.openLayerWindow('wAudit', '<c:url value="/web/admin/repairOrderAudit/auditOrderEdit.action?id="/>' + id, '审核工单')
        }else{
            js.confirm('确认审批通过？', function () {
                var ret = $("#dataGrid").jqGrid('getRowData', id);
                // console.log(ret.auditLevel,ret.level)
                console.log(ret.flowSize)

                if(ret.flowSize == 0 || ret.flowSize == 1) {
                    vLayuiUtil.openLayerIframWindow('wJudge', '<c:url value="/web/admin/repairOrderAudit/judgeOrder.action?id="/>' + id, '审核工单',['60%','60%'])
                } else if(Number(ret.auditLevel)+Number(1)==ret.level&& ret.repairOrderType=="400报修"){
                    vLayuiUtil.openLayerIframWindow('wJudge', '<c:url value="/web/admin/repairOrderAudit/judgeOrder.action?id="/>' + id, '审核工单',['60%','60%'])
                }else{
                    $.ajax({
                        type: 'post',
                        url: "<c:url value="/web/admin/repairOrderAudit/audit.action" />",
                        data: {"repairOrderId": id, "type": type},
                        dataType: 'json',
                        async: false,
                        success: function (data) {
                            js.showMessage(data.msg);
                            $('#dataGrid').dataGrid('refresh');
                        },
                        error: function () {
                            js.showMessage("出错了，请联系管理员");
                        }
                    });
                }
            })

        }

    }


</script>
